An algorithm is just a list of steps described in terms of completely clear instructions for solving a given problem. These instructions start at a specific condition and end with the desired result. A well-written cooking recipe, or the instructions for finding a certain location or address on a map are also algorithms. The term was first used in mathematics, where it is still used.

The word algorithm goes back to the Persian astronomer Muhammad ibn Musa al-Khwarizmi who was born around 780 A.D. He worked in Baghdad, serving the caliph Abdullah al-Mamun, son of the caliph Harun al-Rashid. In medieval times, arithmetic was identified with al-Khwarizmi’s name, and the statement dixit Algorizmi (meaning thus spoke al-Khwarizmi) was a certificate of clarity and authority. His book on algorithms, Hisab al-jabr w’al muqabala, is considered the first text on algebra. The word al-jabr in it also provides the root for “algebra”.

An example of simple mathematical algorithm is the method we know for adding two integers.

Input: Two non-negative integers, let us call them x and y

  • Step 1: Write the integers x and y one under the other with the rightmost digits aligned to the right
  • Step 2: Add the last digits of x and y
  • Step 3: If the sum is less than 10, write than number right under the other two
  • Step 4: If the sum is greater than 10, write the second digit of the sum right under the two, and add the first digit to the sum immediately to the left… and so on

Probably the earliest interesting Western algorithm is the one given in Euclid’s Elements for computing the greatest common divisor of two non-negative integers.

Algorithms gained importance in the West in the 15th century with the introduction of the decimal number system, which allowed for faster calculations when compared to previous Roman numerical system. Algorithms have played a central role in the scientific and technological revolutions in more recent years. Today, humans teach computers algorithms through programming languages.

If there is a problem you can’t solve, then there is an easier problem you can solve: find it. George Pólya

Fill the 3 × 3 table with nine distinct integers from 1 to 9 so that the sum of the numbers in each row, column, and corner-to-corner diagonal is the same.

The Magic Square

Many puzzles can be solved by exhaustive search – a problem-solving strategy that simply tries all possible candidate solutions until a solution to the problem is found. Little creativity is required in order to apply this technique. On the other hand, the limitation of this technique is its inefficiency. In general, the number of candidate solutions that are possible grow very quickly. In many cases, this makes the search for a solution impossible, even with the aid of a computer.

As an example, let us consider how many ways there are to fill 3 x 3 table of the magic square. Let us think of the table as filled with one number at a time, starting with placing the 1 somewhere and ending with placing the 9. There are nine ways to place 1, followed by eight ways to place 2, and so on until the last number 9 is placed in the only unoccupied cell of the table. There are 9 x 8 x . . . x 1 equal to 362,880 ways to arrange the nine numbers in the cells of the 3 × 3 table. Therefore, solving this problem by exhaustive search would mean generating all 362,880 possible arrangements of distinct integers from 1 to 9 in the table and checking, for each of the arrangements, whether all its row, column, and diagonal sums are the same. This amount of work is clearly impossible to do by hand. For now, we just use this problem to show the limitations of exhaustive search. Later, we shall see how to use the structure of the problem to find a solution.

In fact, the number of candidate solutions the exhaustive search algorithm would have to consider becomes too large even for a computer if the table is of size 5 x 5. The number of possibilities 25 x 24 … x 1 would take a computer making 10 trillion operations per second about 49,000 years to finish the job. How big is trillion? It is one followed by twelves zeroes!

Let us next look at an example where it is possible to find a solution using exhaustive search.

A man finds himself on a riverbank with a wolf, a goat, and cabbage. He needs to transport all three to the other side of the river in his boat. However, the boat has room for only the man himself and one other item (either the wolf, the goat, or the cabbage). In his absence, the wolf would eat the goat, and the goat would eat the cabbage. Show how the man can get all these “passengers” to the other side.

It is great if you already know the solution to this problem, given that the problem has an easy solution. This gives us a good opportunity to review some basic principles for solving such problems.

  • Identify what you know by easy to recognize names. In this case, let M, w, g and c represent the man, wolf, goat and cabbage, respectively as shown in the Figure above.
  • Visualize the process of the solution. In the Figure above, the man M, takes the goat g to the other side of the river as the first step of the solution

Fill in the Figure above with the remaining trips that show M taking all these “passengers” to the other side. Is there only one possible solution?

Ahmed and Ayesha are working on a project. Ahmed has a matchbox containing 40 matchsticks. He arranges it in the following manner.

Ahmed counts the number of squares and gets 16 as his answer.

  1. Do you think Ahmed is correct?
  2. How many squares do you count in the Figure above?

Note that 4 small squares make a medium square and 4 medium squares make a big square.


Ayesha challenges Ahmed to remove nine matches from the arrangement such that no squares remain after the removal. Can you help Ahmed by identifying which matches he should remove?


Once upon a time, there was a small world it was a flat world and it was not very wide in fact, it was so thin that if you were not careful you might fall right off the edge in this world was a house and in this house lived a triangle. Her name was Wind. Wind lived all alone and was sometimes sad about that but she was not too lonely because she had a friend who lived just one house over his name was Wr. Ug. Wind often went to visit Mr. Ug. She would walk past the big rock and the pine log to get to Mr. Ug's little yellow house. The problem with Mr. Ug was that he never seemed to be home. So wind did what she always did and left him a message so that he would know that she had been there.

She wrote "Hi Mr. Ug" and hung around a little longer hoping he might come home soon. After waiting a while, she gave up and walked back home, passed the pine log and the big rock to her own little house. When she got back, she saw that someone had left her a message. It said "Hi Wind". Mr. Ug must have come by to see her while she was out trying to see him. She erased the message and decided to go back to his place since he was obviously heading back there as well. Their timing always seemed to be wrong whenever she went to see him. He seemed to be out visiting her. In fact, she had never actually met Mr. Ug, but she felt like she knew him very well because of the messages they were always leaving each other. When she got to his place, she saw that he had already read her message erased it and left again but wind was used to this kind of coincidence so she simply continued their conversation by leaving another message.

Wind asked, "how r u, ritE now" and turned around to go home. Her grammar and spelling were not so good because after all there was no school in her little world. Mr. Ug didn't always have perfect spelling either but wind thought that he had a lovely way with words for example when she got home she found that Mr. Ug had already written a reply. To her how are you message he had said "Nom in' life Nom". She thought this is a beautiful metaphor and felt lucky to have a neighbor who never answered how you are in a boring manner like fine thank you.

What Wind really wanted more than anything was to actually meet him. She decided to try another method. She erased his note and left one saying “BACK SOON”. This way if Mr. Ug came to visit while she was out he would know to stay around for a while until she got back. She decided to get artistic and illustrate it by drawing a foot with wings on the heel. She then rushed back to Mr. Ug's house though it seemed he had taken up a new project. There was a sign-up for a “BUCK ZOO” complete with a picture of a fully antlered buck. Maybe he was out collecting deer for his zoo or just maybe he had gone to visit her. She dashed out a quick “HEllo lEAvinG” and then rushed back to her house. She only found a message that said, “rEvAlue Hello”. It was an interesting message and gave her something to think about. Maybe she was spending too much time trying to greet and talk to Mr. Ug and not enough time on her own projects.

Wind thought maybe there was another path he used since they have never met each other going back and forth. Wind had never explored the world to the left of her house. So, she went left and discovered a few new places. There was a blue rod and a lock pie. However, soon she found herself somewhere familiar. She was back at Mr. Ug's house and as usual, he was not home. Now she knew why they kept missing each other. Their little world was a loop and they were taking different paths from one side to the other. Wind was very excited by this discovery because now she understood her world a little better. She went home and decided to start another project.

Sometimes Wind worried that one of them would accidentally fall off the edge of the world and then she would never get to meet Mr. Ug. She thought about building a fence along the edge. She started with the side below her house and started towards Mr. Ug's house. She passed the big rock and the pine log until she got to Mr. Ug's little yellow house. She saw to her surprise that Mr. Ug was building a fence of his own on the other end of the world. Maybe he had gone to visit her and saw the beginnings of her fence and decided to help. Wind continued building her fence thinking how sweet it was that Mr. Ug was helping with her project. She passed the lock pie and the blue rod and when she got back to her home, she was pleased to see that her entire world was safe.

As her next project, Wind decided to get a pet dog. One day Wind was out watching her dog when the ground started to shake suddenly. The ground began to split. It was an earthquake so powerful that it was ripping her world apart. She quickly got away from the dangerous new edge that was tearing her world. Her dog was still on the other side. She ran trying to get past the crack but the world was now split right down the center all the way around. She could still hear her dog barking, but the sound faded as the two sides of her world separated and drifted apart. Would she ever see her dog again? What about Mr. Ug?

How to make your Mobius Strip

Luckily, you can figure out the ending to this story yourself. Wind lives on not just any loop but a Mobius strip, which you can make easily out of paper. Just cut out a strip and instead of taping it into a normal loop give it a half twist first. If you use a marker that bleeds through the paper, you can draw Wind's house and see it from the other side but all that is essential here is that you draw Wind and her dog. Cut a line down the center of the paper and cut along the line all the way around. How does the story end?/p>